﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Fabrikator;
using FabrikatorDB;

namespace Fabrikatorum.Fabrikator.Sayfa
{
    public partial class BonoPiyasasi : System.Web.UI.Page
    {
        public string uyeno { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["uye"] != null)
            {

                using (FabriDataContext db = new FabriDataContext())
                {
                    Uye girisyapan = (Uye)Session["uye"];
                    uyeno = girisyapan.UyeNo.ToString();
                    //    Bono sinif = new Bono();
                    var bonolar = (from bon in db.BonoTalimats.AsEnumerable().OrderBy(x => Guid.NewGuid()) where bon.UyeNo != girisyapan.UyeNo && bon.Durum == 1 select bon).Take(5);
                    //        var rastgele = (from result in bonolar.AsEnumerable().OrderBy(x => Guid.NewGuid()) select result).Take(5);
                    List<BonoTalimat> listelenecek = new List<BonoTalimat>();
                    foreach (BonoTalimat item in bonolar)
                    {
                        listelenecek.Add(item);
                    }
                    lstBonolar.DataSource = listelenecek;
                    lstBonolar.DataBind();
                }
            }
            else
            {
                Response.Redirect("~/Fabrikator/Sayfa/GirisUyari.html");
            }
        }
        protected string BonoSifrele()
        {
            string sifre = string.Empty;
            Yardimci sinif = new Yardimci();
            string sifrelenecek = uyeno + "-" + Eval("BonoTalimatNo") as string;
            sifre = sinif.Sifrele(sifrelenecek, "bonosatinal");
            return sifre;
        }
    }
}